package com.julinggame.nettyim.handler;

import com.julinggame.nettyim.CommentCode;
import com.julinggame.nettyim.ImServer;
import com.julinggame.nettyim.Result;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

public class ConnectHandler {
   public static void execute(ChannelHandlerContext ctx, CommentCode commentCode) {

       if (ImServer.USER_CHANNEL.containsKey(commentCode.getName())){
           ctx.channel().writeAndFlush(Result.fail("用户名重复"));
           ctx.channel().disconnect();
           return;
       }
       //加入映射表中
        ImServer.USER_CHANNEL.put(commentCode.getName(), ctx.channel());
        //yingshesuccess
       ctx.channel().writeAndFlush(Result.success("系统消息"));

   }
}

